package my.state.headfirst.good;

//可销售状态
public class SoldState implements State {

    //transient 修饰是 proxy 模式中加入的改进
    transient private GunballMachine gunballMachine;

    public SoldState(GunballMachine gunballMachine){
        this.gunballMachine = gunballMachine;
    }
    @Override
    public void insertQuarter() {
        System.out.println("请先出糖果吧！");
    }

    @Override
    public void ejectQuarter() {
        System.out.println("亲，已经出过糖果了，不能退币呀！");
    }

    @Override
    public void turnCrank() {
        System.out.println("亲，别想骗过糖果机出两次糖果");
    }

    @Override
    public void dispense() {
        gunballMachine.releaseBall();
        if(gunballMachine.getCount()>0){
            System.out.println("亲，出糖果成功");
            gunballMachine.setState(gunballMachine.getNoQuarterState());
        }else {
            gunballMachine.setState(gunballMachine.getSoldOutState());
        }
    }
}
